<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%
dim rs,conn
set conn=server.CreateObject("adodb.connection")
set rs=server.CreateObject("adodb.recordset")
filepath=server.MapPath("access\backend\homesmart_customers.mdb")
	
conn.open"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filepath
rs.cursorlocation=3 'adUseClient
rs.cursortype=0 'adOpenForwardOnly 
rs.locktype=1 'adLockReadOnly 
sql="select zip,count(contract_id)/10 as cnt,'' as [customers in 10s] from customers where zip between 80001 and 80100 group by zip order by zip "
rs.open sql, conn

datapoints=rs.recordcount
rs.activeconnection=nothing

ylabel=rs.fields(2).name
yres=300
xres=500
ysize=0

do until rs.eof
	chk=cint(rs(1))
	if chk>ysize then ysize=chk
	rs.movenext
loop

xsize=datapoints*2

yseg=int(yres/ysize)
xseg=int(xres/xsize)

for x=1 to 4
	spcr=spcr & "&nbsp;"
next
%>

<head>
<title>chart</title>
<style type="text/css">
table {border:#000000; border-style:solid; border-width:1px}
td {border-right:#CCCCCC;
	 border-left:#CCCCCC; 
	 border-bottom:#0033FF; 
	 border-top:none; 
	 border-left-style:solid;
	 border-right-style:solid;
	 border-top-style:none; 
	 border-width:1px;
	 background-color:#eeeeee;
}
.yaxisvalues {
	vertical-align:top;
	border-right:thick;
	border-right-color:#000000;
	 border-left:none; 
	 border-bottom:none; 
	 border-top:#0033FF; 
	 border-top-style:solid; 
	 border-top-width:1px;
	 background-color:#cccccc;
	 width:100px;
	 text-align:right;
	 font-size:12px;
	 font-weight:bold;
	 font-family:Arial, Helvetica, sans-serif
}
.yaxislabel {
	width:100px;
	background-color:#bbbbbb;
	text-align:center;
	vertical-align:top;
	font-family:Arial, Helvetica, sans-serif;
	font-weight:bold
}
.xaxislabel {
	background-color:#bbbbbb;
	text-align:center;
	font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
	vertical-align:top;
	font-weight:bold
}
	
</style>
</head>
<body>
<table align="center" border="1" bordercolor="#000000">
<tr>
 <td>
  <table cellpadding="0" cellspacing="0" width="<%= xres %>" height="<%= yres %>" bordercolor="#FFFFFF">
  <tr>
  <% for x=1 to len(ylabel)
  	ylbl=ylbl & mid(ylabel,x,1) & "<br>"
	next %>
   <td rowspan="<%= ysize+2 %>" class="yaxislabel"><%= ylbl %>
   </td>
   </tr>
  <% for y=ysize to 1 step-1 %>
   <tr>
    <td id="ylabel<%= y %>" class="yaxisvalues"></td>
   <% for x=1 to xsize %>
    <td id="<%= y %>-<%= x %>" width="<%= xseg %>" height="<%= yseg %>" style="border-bottom-style:dotted"><%= spcr %></td>
   <% next %>
   </tr>
  <% next %>
  <tr>
  <td></td>
  <% for x=1 to xsize+1 %>
  <td id="xlabel<%= x %>" class="xaxislabel"</td>
  <% next %>
</table>
</td>
</tr>
</table>
<script type="text/vbscript">
ysize=<%= ysize %>
xsize=<%= xsize %>

dim data(<%= datapoints %>)
dim item(<%= datapoints %>)
<% rs.movefirst %>
<% for dl=1 to datapoints %>
data(<%= dl %>) = <%= rs(1) %>
item(<%= dl %>) = "<%= rs(0) %>"
<% rs.movenext %>
<% next %>

dcnt=cint(ubound(data))
xscale=int(xsize/dcnt)
yscale=ysize
dim xcor(),ycor()
redim xcor(dcnt)
redim ycor(dcnt)

for x=0 to dcnt-1
	xcor(x+1)=(x*xscale)+1
	ycor(x+1)=int(data(x+1))
next

for x=ysize to 1 step-1
	document.getElementById("ylabel" & x).innertext=x
next 

for x=0 to dcnt-1
	xlbl=""
	for xl=1 to len(item(x+1))
		xlbl=xlbl & mid(item(x+1),xl,1) & "<br>"
	next
	document.getElementById("xlabel" & xcor(x+1)).innerhtml=xlbl
	for yfill=1 to ycor(x+1)
		document.getElementById(yfill & "-" & xcor(x+1)).style.backgroundcolor="#00CC00"
	next
next
</script>
</body>
</html>
<%
rs.close
conn.close
set rs=nothing
set conn=nothing
%>